/**
 * @program: LeetCode
 * @description: LeetCode :剑指 Offer 57. 和为s的两个数字
 * @author: WXY
 * @create: 2022-12-10 21:11
 * @Version 1.0
 **/


public class Num057_twoSum {
    public int[] twoSum(int[] arr, int target) {
        if (arr == null || arr.length < 2) {
            return new int[]{};
        }
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            if (arr[left] + arr[right] < target) {
                left++;
            } else if (arr[left] + arr[right] > target) {
                right--;
            } else {
                break;
            }
        }
        return new int[]{arr[left], arr[right]};
    }
}
